{% extends "base.html" %}
{% import "/sideview/macros.html" as sideview %}

{% block title %}会员管理{% endblock title %}
{% block subtitle %}会员管理{% endblock subtitle %}

{% block content %}
    {% set sfl = request.query_params.get("sfl", "") %}
    {% set stx = request.query_params.get("stx", "") %}

    <div class="local_ov01 local_ov">
        <a href="/admin/member_list" class="ov_listall">完整列表</a>
        <span class="btn_ov01">
            <span class="ov_txt">成员总数</span>
            <span class="ov_num">{{ total_count|number_format }}姓名</span>
        </span>
        <a href="{{ request.url.include_query_params(sst="mb_intercept_date", sod="desc") }}" class="btn_ov01" 
            data-tooltip-text="按被阻止的顺序排序.&#xa;输出整个数据.">
            <span class="ov_txt">阻塞</span>
            <span class="ov_num">{{ intercept_count|number_format }}姓名</span>
        </a>
        <a href="{{ request.url.include_query_params(sst="mb_leave_date", sod="desc") }}" class="btn_ov01"
            data-tooltip-text="按取款顺序排序.&#xa;输出整个数据.">
            <span class="ov_txt">撤回</span>
            <span class="ov_num">{{ leave_count|number_format }}姓名</span>
        </a>
    </div>

    <form id="fsearch" name="fsearch" class="local_sch01 local_sch" method="get">
        <label for="sfl" class="blind">搜索目标</label>
        <select name="sfl" id="sfl">
            <option value="mb_id" {{ get_selected('mb_id', sfl) }}>会员Id</option>
            <option value="mb_nick" {{ get_selected('mb_nick', sfl) }}>昵称</option>
            <option value="mb_name" {{ get_selected('mb_name', sfl) }}>姓名</option>
            <option value="mb_level" {{ get_selected('mb_level', sfl) }}>权利(Level)</option>
            <option value="mb_email" {{ get_selected('mb_email', sfl) }}>E-Mail</option>
            <option value="mb_tel" {{ get_selected('mb_tel', sfl) }}>电话号码</option>
            <option value="mb_hp" {{ get_selected('mb_hp', sfl) }}>移动电话号码</option>
            <option value="mb_point" {{ get_selected('mb_point', sfl) }}>点</option>
            <option value="mb_datetime" {{ get_selected('mb_datetime', sfl) }}>时间加入</option>
            <option value="mb_ip" {{ get_selected('mb_ip', sfl) }}>IP地址</option>
            <option value="mb_recommend" {{ get_selected('mb_recommend', sfl) }}>推荐人</option>
        </select>
        <label for="stx" class="blind">搜索词<strong class="blind"> 必不可少的</strong></label>
        <input type="text" name="stx" value="{{ stx }}" id="stx" required class="required frm_input">
        <button type="submit" class="btn_submit">
          <span class="blind">搜索</span>
        </button>
    </form>

    <div class="local_desc01 local_desc">
        <p>
            成员的idia，以防止其他成员在删除成员材料时使用其现有成员的idia, 姓名, 我永久保留昵称而不删除它.
        </p>
    </div>

    <form name="fmemberlist" id="fmemberlist" action="/admin/member_list_update" onsubmit="return fmemberlist_submit(this);" method="post">
        <input type="hidden" name="token" value="">

        <div class="tbl_head01 tbl_wrap">
            <table>
                <caption>会员管理列表</caption>
                <thead>
                    <tr>
                        <th scope="col" id="mb_list_chk" rowspan="2">
                            <label for="chkall" class="blind">成员全部</label>
                            <input type="checkbox" name="chkall" value="1" id="chkall" onclick="check_all(this.form)">
                        </th>
                        <th scope="col" id="mb_list_id" colspan="2">{{ subject_sort_link(request, 'mb_id')|safe }}Idie</a></th>
                        <th scope="col" id="mb_list_auth">状态</th>
                        <th scope="col" id="mb_list_mailc">{{ subject_sort_link(request, 'mb_email_certify')|safe }}邮件身份验证</a></th>
                        <th scope="col" id="mb_list_cert">{{ subject_sort_link(request, 'mb_certify')|safe }}检查你自己的</a></th>
                        <th scope="col" id="mb_list_adultc">{{ subject_sort_link(request, 'mb_adult')|safe }}成人认证</a></th>
                        <th scope="col" id="mb_list_open" rowspan="2">{{ subject_sort_link(request, 'mb_open')|safe }}信息披露</a></th>
                        <th scope="col" id="mb_list_mobile">移动电话</th>
                        <th scope="col" id="mb_list_lastcall">{{ subject_sort_link(request, 'mb_today_login')|safe }}最终访问</a></th>
                        <th scope="col" id="mb_list_grp">访问组</th>
                        <th scope="col" rowspan="2" id="mb_list_mng">管理</th>
                    </tr>
                    <tr>
                        <th scope="col" id="mb_list_name">{{ subject_sort_link(request, 'mb_name')|safe }}姓名</a></th>
                        <th scope="col" id="mb_list_nick">{{ subject_sort_link(request, 'mb_nick')|safe }}昵称</a></th>
                        <th scope="col" id="mb_list_deny">{{ subject_sort_link(request, 'mb_level')|safe }}权利(Level)</a></th>
                        <th scope="col" id="mb_list_mailr">{{ subject_sort_link(request, 'mb_mailling')|safe }}接收邮件</a></th>
                        <th scope="col" id="mb_list_sms">{{ subject_sort_link(request, 'mb_sms')|safe }}SMS收货</a></th>
                        <th scope="col" id="mb_list_auth">{{ subject_sort_link(request, 'mb_intercept_date')|safe }}访问阻止</a></th>
                        <th scope="col" id="mb_list_tel">电话号码</th>
                        <th scope="col" id="mb_list_join">{{ subject_sort_link(request, 'mb_datetime')|safe }}加入天数</a></th>
                        <th scope="col" id="mb_list_join">{{ subject_sort_link(request, 'mb_datetime')|safe }}加入天数</a></th>
                        <th scope="col" id="mb_list_point">{{ subject_sort_link(request, 'mb_point')|safe }}点</a></th>
                    </tr>
                </thead>
                <tbody>
                    {% for member in members %}
                        {% set background_color = 'bg0' if loop.index0 % 2 == 0 else 'bg1' %}
                        <tr class="{{ background_color }}">
                        <td headers="mb_list_chk" class="td_chk" rowspan="2">
                            <input type="hidden" name="mb_id[]" value="{{ member.mb_id }}" id="mb_id_{{ loop.index0 }}">
                            <label for="chk_{{ loop.index0 }}" class="blind">{{ member.mb_name }}亲爱的</label>
                            <input type="checkbox" name="chk[]" value="{{ loop.index0 }}" id="chk_{{ loop.index0 }}">
                        </td>
                        <td headers="mb_list_id" colspan="2" class="td_name sv_use">{{ member.mb_id }}</td>
                        <td headers="mb_list_auth" class="td_mbstat"><!-- 状态 -->
                            {% if member.mb_leave_date %}
                                <span class="mb_leave_msg" title="{{ member.mb_leave_date }}">撤回了</span>
                            {% elif member.mb_intercept_date %}
                                <span class="mb_intercept_msg" title="{{ member.mb_intercept_date }}">已阻塞</span>
                            {% else %}
                                正常
                            {% endif %}
                        </td>
                        <td headers="mb_list_mailc"><!-- 邮件身份验证 -->
                            {% if is_none_datetime(member.mb_email_certify) %}
                                <span class="txt_false">No</span>
                            {% else %}
                                <span class="txt_true">Yes</span>
                            {% endif %}
                        </td>
                        <td headers="mb_list_cert" class="td_mbcert"><!-- 检查你自己的 -->
                            {% if member.mb_certify == '' %}未经认证
                            {% elif member.mb_certify == 'simple' %}简单身份验证
                            {% elif member.mb_certify == 'hp' %}移动电话
                            {% elif member.mb_certify == 'ipin' %}ipin
                            {% endif %}
                        </td>
                        <td headers="mb_list_adultc">
                            <label for="mb_adult_{{ loop.index0 }}" class="blind">成人认证</label>
                            {% if member.mb_adult %}
                                <span class="txt_true">Yes</span>
                            {% else %}
                                <span class="txt_false">No</span>
                            {% endif %}
                        </td>
                        <td headers="mb_list_open" rowspan="2">
                            <label for="mb_open_{{ loop.index0 }}" class="blind">信息披露</label>
                            <input type="checkbox" name="mb_open[]" value="{{ loop.index0 }}" id="mb_open_{{ loop.index0 }}" {{ 'checked' if member.mb_open }}>
                        </td>
                        <td headers="mb_list_mobile" class="td_tel"><!-- 移动电话号码 -->{{ member.mb_hp }}</td>
                        <td headers="mb_list_lastcall" class="td_date"><!-- 最近访问的天数 -->{{ member.mb_today_login }}</td>
                        <td headers="mb_list_grp" class="td_numsmall">
                            <a href="/admin/boardgroupmember_form/{{ member.mb_id }}">{{ member.group_count|number_format }}</a>
                        </td>
                        <td headers="mb_list_mng" rowspan="2" class="td_mng td_mng_s">
                            <a href={{ "/admin/member_form/" ~ member.mb_id|set_query_params(request) }} class="btn btn_03">校正</a>
                            <a href="/admin/boardgroupmember_form/{{ member.mb_id }}" class="btn btn_02">组</a></td>
                    </tr>
                    <tr class="{{ background_color }}">
                        <td headers="mb_list_name" class="td_mbname">{{ member.mb_name }}</td>
                        <td headers="mb_list_nick" class="td_name sv_use"><!-- 昵称 -->
                            {{ sideview.get(request, member.mb_id, member.mb_name, member.mb_email, member.mb_homepage)|safe }}
                        </td>
                        <td headers="mb_list_auth" class="td_mbstat"><!-- 权利(level) -->
                            {{ get_member_level_select('mb_level[]', 1, admin.mb_level if admin else 1, member.mb_level if member else 1)|safe }}
                        </td>
                        <td headers="mb_list_mailr">
                            <label for="mb_mailling_0" class="blind">接收邮件</label>
                            <input type="checkbox" name="mb_mailling[]" value="{{ loop.index0 }}" id="mb_mailling_{{ loop.index0 }}" {{ 'checked' if member.mb_mailling }}>
                        </td>
                        <td headers="mb_list_sms">
                            <label for="mb_sms_0" class="blind">SMS收货</label>
                            <input type="checkbox" name="mb_sms[]"  value="{{ loop.index0 }}" id="mb_sms_{{ loop.index0 }}" {{ 'checked' if member.mb_sms }}>
                        </td>
                        <td headers="mb_list_deny"><!-- 访问阻止 -->
                            <input type="checkbox" name="mb_intercept_date[]"  value="{{ loop.index0 }}" id="mb_intercept_date_{{ loop.index0 }}" title="粗体" {{ 'checked' if member.mb_intercept_date }}>
                            <label for="mb_intercept_date_{{ loop.index0 }}" class="blind">访问阻止</label>
                        </td>
                        <td headers="mb_list_tel" class="td_tel"><!-- 电话号码 -->{{ member.mb_tel }}</td>
                        <td headers="mb_list_join" class="td_date"><!--会员天数 -->{{ member.mb_datetime }}</td>
                        <td headers="mb_list_point" class="td_num">
                            <a href="/admin/point_list?sfl=mb_id&stx={{ member.mb_id }}">{{ member.mb_point|number_format }}</a>
                        </td>
                    </tr>
                    {% else %}
                        <tr>
                            <td colspan="12" class="empty_table">没有材料.</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <div class="btn_fixed_top">
            <input type="submit" name="act_button" value="选择校正" onclick="document.pressed=this.value" class="btn btn_02">
            <input type="submit" name="act_button" value="删除所选内容" onclick="document.pressed=this.value" class="btn btn_02">
            <a href="/admin/member_form" id="member_add" class="btn btn_01">添加成员</a>
        </div>
    </form>

    {{ paging|safe }}

    <script>
        function fmemberlist_submit(f) {
            if (!is_checked("chk[]")) {
                alert(document.pressed + " 选择您想要的一个或多个项目.");
                return false;
            }

            if (document.pressed == "删除所选内容") {
                if (!confirm("是否确实要删除所选材质?")) {
                    return false;
                }

                f.action = "/admin/member_list_delete";
            }

            f.token.value = generate_token();
            f.action += "?{{ request.query_params|safe }}";

            return true;
        }
    </script>
{% endblock content %}